# _*_ coding: utf-8 _*_
from odoo import models, api, fields


class ProductTemplate(models.Model):
    _inherit = "product.template"

    @api.onchange("categ_id")
    @api.multi
    def _onchange_categ_id(self):
        self.ensure_one()
        template = self
        res = {
            "value": {}
        }
        if template.categ_id:
            Setting = self.env["product.category.attribute.setting"]
            attributes = Setting.get_attributes_by_category(template.categ_id.id)
            attribute_line_vals = [(0, 0, {
                "attribute_id": category.id
            }) for category in attributes]
            res["value"]["attribute_line_ids"] = attribute_line_vals
        return res
